package supermarket1;

public class Merchandise {
    public String name;
    private String id;
    private int count;
    private double soldPrice;
    private double purchasePrice;
    private String gift;//每个商品有个赠品

    public void setName(String name){
        this.name=name;
    }
    public String getName(){
        return this.name;
    }
    public void setId(String id){
        this.id=id;
    }
    public String getId(){
        return this.id;
    }
    public Merchandise(String name,String id,int count,double soldPrice,double purchasePrice){
        this.name=name;
        this.id=id;
        this.count=count;
        this.soldPrice=soldPrice;
        this.purchasePrice=purchasePrice;
    }
    //TODO 无参构造函数
    public Merchandise(){
        this("无名","000",20,30,10);
    }

    public void describe(){

        System.out.println("您选购的商品名字为"+name
                +"。单价为"+soldPrice+"元。赠品为"+gift+"库存为"+count);
    }

    public double buy(int count){
        if(this.count<count){
            return -1;
        }
        this.count-=count;
        double totalCost=count*soldPrice;
        return totalCost;
    }
}
